<CFSET sMessPostApproval="">
<CFQUERY NAME="qryCINLEAVEAPPSM" DATASOURCE="#client.company_dsn#">
	SELECT *
	FROM CINLEAVEAPPSM
	WHERE ROUTEID = '#GetRecord.ROUTEID#'
</CFQUERY>

<CFIF qryCINLEAVEAPPSM.RecordCount>
	<CFIF qryCINLEAVEAPPSM.LEAVETYPE IS "BL">
		<!--- for Birthday leave and bereavement leave only --->
		<!--- get employmentstatus in CMFPA --->
		<CFQUERY NAME="qryCMFPA" DATASOURCE=#client.company_dsn#>
			SELECT EMPLOYMENTSTATUS
			FROM CMFPA
			WHERE PERSONNELIDNO = '#qryCINLEAVEAPPSM.PERSONNELIDNO#'
		</CFQUERY>
		
		<CFIF qryCMFPA.RecordCount>
			<CFTRANSACTION>
			<CFTRY>				
				<CFQUERY NAME="qryUpdateCINLEAVEAPPSM" DATASOURCE="#client.company_dsn#">
					UPDATE CINLEAVEAPPSM
					SET WITHPAY = <CFIF UCase(qryCMFPA.EMPLOYMENTSTATUS) IS "REGULAR">'Y'<CFELSE>'N'</CFIF>
					WHERE DOCNUMBER = '#qryCINLEAVEAPPSM.DOCNUMBER#'
				</CFQUERY>
				
				<CFTRANSACTION ACTION="COMMIT"/>						
				
				<CFCATCH TYPE="Database">
					<CFTRANSACTION ACTION="ROLLBACK"/>
					<CFSET sMessPostApproval="Error in post-approval activity ...<br><br>#CFCATCH.message# #CFCATCH.DETAIL#">
				</CFCATCH>
			</CFTRY>
			</CFTRANSACTION>				
		<CFELSE>
			<CFSET sMessPostApproval="WARNING!!! Unable to validate employment status. Employent status is missing.<BR>Please contact your administrator.">
		</CFIF>
	<CFELSEIF qryCINLEAVEAPPSM.LEAVETYPE IS "PL">
		<!--- for day-off leave only --->
		<CFTRANSACTION>
		<CFTRY>				
			<CFQUERY NAME="qryUpdateCINLEAVEAPPSM" DATASOURCE="#client.company_dsn#">
				UPDATE CINLEAVEAPPSM
				SET WITHPAY = 'Y'
				WHERE DOCNUMBER = '#qryCINLEAVEAPPSM.DOCNUMBER#'
			</CFQUERY>
			
			<CFTRANSACTION ACTION="COMMIT"/>						
			
			<CFCATCH TYPE="Database">
				<CFTRANSACTION ACTION="ROLLBACK"/>
				<CFSET sMessPostApproval="Error in post-approval activity ...<br><br>#CFCATCH.message# #CFCATCH.DETAIL#">
			</CFCATCH>
		</CFTRY>
		</CFTRANSACTION>				
	<CFELSEIF qryCINLEAVEAPPSM.LEAVETYPE IS "RL" OR qryCINLEAVEAPPSM.LEAVETYPE IS "ML">
		<!--- for day-off leave only --->
		<CFTRANSACTION>
		<CFTRY>				
			<CFQUERY NAME="qryUpdateCINLEAVEAPPSM" DATASOURCE="#client.company_dsn#">
				UPDATE CINLEAVEAPPSM
				SET WITHPAY = 'N'
				WHERE DOCNUMBER = '#qryCINLEAVEAPPSM.DOCNUMBER#'
			</CFQUERY>
			
			<CFTRANSACTION ACTION="COMMIT"/>						
			
			<CFCATCH TYPE="Database">
				<CFTRANSACTION ACTION="ROLLBACK"/>
				<CFSET sMessPostApproval="Error in post-approval activity ...<br><br>#CFCATCH.message# #CFCATCH.DETAIL#">
			</CFCATCH>
		</CFTRY>
		</CFTRANSACTION>				
	</CFIF>
<CFELSE>
	<CFSET sMessPostApproval="WARNING!!! Unable to validate employment status. Application is missing.<BR>Please contact your administrator.">
</CFIF> <!--- RouteID not found in CINLVAPPSI --->
